HAL CEC I/O operation functions migration

This section provides information about the HAL CEC I/O operation functions migration.

Note

The main difference between HAL1 and HAL2 include the following points:

  • Rename of some functions to follow a unified naming convention.

  • The functions related to transmit and receive use new structures to handle CEC headers and data separately.

  • The function parameters have been updated to reflect these structural changes.

HAL CEC set the logical device address

HAL1

HAL2

Function prototype

HAL_CEC_SetDeviceAddress(CEC_HandleTypeDef *hcec,
                uint16_t CEC_OwnAddress);
HAL_CEC_SetConfig(hal_cec_handle_t *hcec,
            const hal_cec_config_t *p_config);

Example usage

CEC_HandleTypeDef hcec;

uint16_t my_addr = 0x01;
HAL_CEC_SetDeviceAddress(&hcec, my_addr);
hal_cec_handle_t hcec;
hal_cec_config_t cfg;
cfg.own_address = 0x01;
HAL_CEC_SetConfig(&hcec, &cfg);

Related concept:

Related use case:


HAL CEC message transmit using interrupt mode

HAL1

HAL2

Function prototype

HAL_CEC_Transmit_IT(CEC_HandleTypeDef *hcec, uint8_t InitiatorAddress,
             uint8_t DestinationAddress,
             const uint8_t *pData, uint32_t Size);
HAL_CEC_Transmit_IT(hal_cec_handle_t *hcec, const hal_cec_header_t *p_tx_header,
             const void *p_tx_data, uint32_t tx_size_byte);

Example usage

CEC_HandleTypeDef hcec;

uint8_t initiator = 0x01;
uint8_t destination = 0x05;

uint8_t data[] = { 0x44, 0x41 };
uint32_t size = sizeof(data);

HAL_CEC_Transmit_IT(&hcec, initiator, destination, data, size);
hal_cec_handle_t hcec;
hal_cec_header_t tx_header;
tx_header.initiator_address = 0x01;
tx_header.destination_address = 0x05;

uint8_t tx_data[] = { 0x44, 0x41 };
uint32_t tx_size = sizeof(tx_data);

HAL_CEC_Transmit_IT(&hcec, &tx_header, tx_data, tx_size);

Related use case:


HAL CEC get the size of the last received frame

HAL1

HAL2

Function prototype

HAL_CEC_GetLastReceivedFrameSize(const CEC_HandleTypeDef *hcec);
The amount of received data can be retrieved as a parameter by HAL_CEC_RxCpltCallback() in IT mode or by HAL_CEC_PollForReception() in polling mode.

Example usage

CEC_HandleTypeDef hcec;
uint32_t size = HAL_CEC_GetLastReceivedFrameSize(&hcec);
// Polling mode
hal_cec_handle_t hcec;
uint32_t size = 0;
if (HAL_CEC_PollForReception(&hcec, 100U, &size) == HAL_OK) {
    // 'size' contains the received data size in bytes
}

// Interrupt mode
void HAL_CEC_RxCpltCallback(hal_cec_handle_t *hcec, uint32_t received_size_byte)
{
    // 'received_size_byte' contains the received data size in bytes
}

HAL CEC change the receive data buffer

In HAL2 the API is renamed to HAL_CEC_SetRxBuffer and the parameters are updated to use the new structure.
  • *Rxbuffer in HAL1 is split to p_rx_header and p_rx_data in HAL2.

  • rx_max_size_byte is added to specify the maximum size of the receive buffer.

  • Due to the split, the payload buffer in HAL2 (p_rx_data) holds only the data bytes and not the header. Therefore, for the same total frame size, p_rx_data capacity is typically one byte less than the HAL1 Rxbuffer.

HAL1

HAL2

Function prototype

HAL_CEC_ChangeRxBuffer(CEC_HandleTypeDef *hcec, uint8_t *Rxbuffer);
HAL_CEC_SetRxBuffer(hal_cec_handle_t *hcec, hal_cec_header_t *p_rx_header,
             void *p_rx_data, uint32_t rx_max_size_byte);

Example usage

CEC_HandleTypeDef hcec;

uint8_t rx_buf[32];

HAL_CEC_ChangeRxBuffer(&hcec, rx_buf);
hal_cec_handle_t hcec;
hal_cec_header_t rx_header;
uint8_t rx_data[31];
uint32_t rx_max_size = sizeof(rx_data);

HAL_CEC_SetRxBuffer(&hcec, &rx_header, rx_data, rx_max_size);

Related use case: